﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SQLExecute;

public partial class admin_settings : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] != null && Session["groupid"].ToString() == "4")
        {
            BindGrid();
            lUsername.Text = Session["username"].ToString();
        }
        else { Response.Redirect("../login.aspx"); }
    }

    protected void lnkLogout_Click(object sender, EventArgs e)
    {
        //FormsAuthentication.SignOut();

        Session.Clear();
        Response.Redirect("../login.aspx");
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        DateTime dateResultTuNgay;
        CultureInfo culture;
        DateTimeStyles styles = DateTimeStyles.None;

        culture = CultureInfo.CreateSpecificCulture("fr-FR");

        //Common c = new Common();        
        NghiPhep n = new NghiPhep();
        DateTime.TryParse(txtFromDate.Text,culture,styles,out dateResultTuNgay);

        n.Insert_Nghi_Bat_Buoc(dateResultTuNgay, Convert.ToDouble(txtSoNgay.Text.Trim()), txtNote.Text);
        ClearText();
        BindGrid();
    }
    protected void ClearText()
    {
        txtFromDate.Text = "";
        txtSoNgay.Text = "";
        txtNote.Text = "";
    }
    protected void BindGrid()
    {
        string query = "select * from tbl_nghibatbuoc";
        DataSet ds = SqlHelper.ExecuteDataset(Common.strConnect, CommandType.Text, query);
        dgNghiBatBuoc.DataSource = ds;
        dgNghiBatBuoc.DataBind();

     }
    protected void dgNghiBatBuoc_RowCommand(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewRowCommandEventArgs e)
    {
        int id;
        string query;
        if (e.CommandArgs.CommandName == "XoaNghiBatBuoc")
        {
            id = (int)dgNghiBatBuoc.GetRowValues(e.VisibleIndex, "id");

            query = "delete tbl_nghibatbuoc where id='" + id + "'";
            SqlHelper.ExecuteNonQuery(Common.strConnect, CommandType.Text, query);
        }
        BindGrid();
    }
}
